<template>
    <div class="upload-detail-page">
      <div class="detail-container">
        <!-- 返回按钮 -->
        <div class="back-button" @click="handleBack">
          <span>← 返回</span>
        </div>
  
        <!-- 加载状态显示 -->
        <div v-if="loading" class="loading">
          加载中...
        </div>
  
        <!-- 错误信息显示 -->
        <div v-else-if="error" class="error-message">
          {{ error }}
        </div>
  
        <!-- 主要内容区域 -->
        <div v-else class="content-section">
          <!-- 图片/视频展示区域 -->
          <div class="media-section">
            <img :src="uploadData.image" alt="上传内容" class="preview-image">
            <h3 class="section-title"></h3>
          </div>
  
          <!-- 文字信息区域 -->
          <div class="text-section">
            <!-- 简单说明 -->
            <div class="info-group">
              <h3 class="section-title">简单说明</h3>
              <div class="info-content">{{ uploadData.simpleDescription }}</div>
            </div>
  
            <!-- 详细说明 -->
            <div class="info-group">
              <h3 class="section-title">详细说明</h3>
              <div class="info-content">{{ uploadData.detailedDescription }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </template>
  
  <script>
  import { ref, onMounted } from 'vue';
  import { useRouter, useRoute } from 'vue-router';
  import axios from 'axios';

  export default {
    name: 'UploadDetail',
    setup() {
      const router = useRouter();
      const route = useRoute();
      const uploadData = ref({
        image: '',
        simpleDescription: '',
        detailedDescription: ''
      });
      const loading = ref(true);
      const error = ref(null);

      const handleBack = () => {
        router.back();
      };

      onMounted(async () => {
        const id = route.params.id;
        try {
          const response = await axios.get(`http://127.0.0.1:8080/data/${id}`);
          const record = response.data.records[0];
          
          // 将API返回的数据映射到组件的数据结构
          uploadData.value = {
            image: record.pictures,
            simpleDescription: record.title,
            detailedDescription: record.record_intro
          };
        } catch (error) {
          console.error('获取上传记录失败:', error);
          error.value = '获取数据失败，请稍后重试';
        } finally {
          loading.value = false;
        }
      });

      return {
        uploadData,
        loading,
        error,
        handleBack
      };
    }
  }
  </script>
  
  <style scoped>
  .upload-detail-page {
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
    margin-top: 80px;
  }
  
  .detail-container {
    background: #ffffff;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  }
  
  .back-button {
    margin-bottom: 20px;
    cursor: pointer;
    display: inline-block;
    padding: 10px 20px;
    background-color: #f5f5f5;
    border-radius: 4px;
    transition: all 0.3s ease;
  }
  
  .back-button:hover {
    background-color: #e0e0e0;
  }
  
  .content-section {
    display: flex;
    gap: 40px;
  }
  
  .media-section {
    flex: 1;
  }
  
  .text-section {
    flex: 1;
  }
  
  .preview-image {
    width: 100%;
    max-height: 400px;
    object-fit: contain;
    border-radius: 8px;
    margin-bottom: 20px;
  }
  
  .section-title {
    font-size: 18px;
    color: #333;
    margin-bottom: 15px;
    font-weight: bold;
  }
  
  .info-group {
    margin-bottom: 30px;
  }
  
  .info-content {
    padding: 15px;
    background-color: #f5f7fa;
    border-radius: 4px;
    line-height: 1.6;
    color: #606266;
  }
  
  @media (max-width: 768px) {
    .content-section {
      flex-direction: column;
    }
  
    .upload-detail-page {
      padding: 10px;
    }
  
    .detail-container {
      padding: 15px;
    }
  }
  
  .loading {
    text-align: center;
    padding: 20px;
    color: #909399;
  }
  
  .error-message {
    text-align: center;
    padding: 20px;
    color: #f56c6c;
    background-color: #fef0f0;
    border-radius: 4px;
  }
  </style>